✞ ☎
<?php

class ShopProduct {
private $title = '商 品 名称 ';
private $producerName = '制 造 商 名称 ';
private $place = '产地 ';
protected $price = 0;
private $discount = 0;
function __construct( $title, $producerName , $place, $price ) {
$this->title = $title;
$this->producerName = $producerName;
$this ->place = $place;
$this->price = $price;
}
function getTitle() {
return $this->title;
}
function getProducerName() {
return $this->producerName;
}
function getPlace() {
return $this->place;
}
function setDiscount( $num ) {
$this->discount = $num;
}
function getDiscount() {
return $this->discount;
}
function getPrice() {
return $this->price - $this->price*$this->discount;
}
function getProducer() {
return "$this->place" . "$this->producerName";
}
function getSummaryLine() {
$base = "$this->title" . "\t" . "$this->place" . "\t" . "$this->
producerName";
return $base;
}
}

class ShopProductWriter {
public function write( $shopProduct ) {
$str = $shopProduct ->getTitle() . ":" . $shopProduct ->getProducer
() . $shopProduct ->getPrice() . "\n";
print $str;
}
}

$product1 = new ShopProduct( "《洗 脑 术》", '中 国 青 年 出 版社', '北京',
32 );
$writer = new ShopProductWriter();
$writer->write( $product1 );
class SPWriter {
function write( ShopProduct  ) {
$str = "商 品 名 称：" . $shopProduct ->getTitle() . "\t" .
"生 产 商：" . $shopProduct ->getProducer() . ":\t" .
"价 格：" . $shopProduct ->getPrice() . "\n";
print $str;
}
}
$product1 = new ShopProduct( "《洗 脑 术》", '中 国 青 年 出 版社', '北京',
32 );
$writer = new SPWriter();
$writer->write( $product1 );
$writer->write( '测 试 字符' );
?>